
//token的获取与存储
import 'package:shared_preferences/shared_preferences.dart';

class TokenManager {
  static const String _tokenKey = 'user_token';

  // 保存Token
  static Future<void> saveToken(String token) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.setString(_tokenKey, token);
  }

  // 获取Token
  static Future<String?> getToken() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.getString(_tokenKey);
  }

  // 清除Token
  static Future<void> clearToken() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.setString(_tokenKey, "");
  }
//   // 保存Token
//   await TokenManager.saveToken('your_token');
//
// // 获取Token
//   String? token = await TokenManager.getToken();
//   print('Token: $token');
//
// // 清除Token
//   await TokenManager.clearToken();
}
//存储城市列表版本
class CityListVersionManager{
  static const String CityListVersion="0";

  // 保存城市列表版本
  static Future<void> saveCityListVersion(String citylistversion) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.setString(CityListVersion as String, citylistversion as String);
  }

  // 获取城市列表版本
  static Future<String?> getCityListVersion() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.getString(CityListVersion);
  }

  // 清除
  static Future<void> clearCityListVersion() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.remove(CityListVersion);
  }
}
//存储城市列表
class CityListManager{
  static const String CityList="0";

  // 保存城市列表
  static Future<void> saveCityList(String citylist) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.setString(CityList as String, citylist as String);
  }

  // 获取城市列表
  static Future<String?> getCityList() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.getString(CityList);
  }

  // 清除
  static Future<void> clearCityList() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.remove(CityList);
  }
}
//已联系的司机
class ContactedDriverMaganer{
  static const String ContactedDriverList="0";

  // 保存已联系的司机
  static Future<void> saveCityList(String citylist) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.setString(ContactedDriverList as String, citylist as String);
  }

  // 获取已联系的司机
  static Future<String?> getCityList() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.getString(ContactedDriverList);
  }

  // 清除已联系的司机
  static Future<void> clearCityList() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.remove(ContactedDriverList);
  }
}
//userId的获取与存储
class UserIdManager {
  static const String _userId = 'userID';

  // 保存userId
  static Future<void> saveUserID(String userId) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.setString(_userId, userId);
  }

  // 获取userId
  static Future<String?> getUserID() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.getString(_userId);
  }

  // 清除userId
  static Future<void> clearUserID() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.setString(_userId, "");
  }
}
//手机号的获取与存储
class PhoneNumManager {
  static const String pnhonNum = 'Phone';

  // 保存
  static Future<void> savePhone(String phoneNum) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.setString(pnhonNum, phoneNum);
  }

  // 获取
  static Future<String?> getPhone() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.getString(pnhonNum);
  }

  // 清除
  static Future<void> clearPhone() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.remove(pnhonNum);
  }
}

//历史地址
class HisAddressManager {
  static const String _keyAddresses = 'Addresses';

  // 保存地址列表
  static Future<void> saveAddresses(List<String> addresses) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.setStringList(_keyAddresses, addresses);
  }

  // 获取地址列表
  static Future<List<String>?> getAddresses() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.getStringList(_keyAddresses);
  }

  // 清除地址列表
  static Future<void> clearAddresses() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.remove(_keyAddresses);
  }
}
//历史货物名称
class HisGoodsNameManager {
  static const String _keyGoodsName = 'GoodsName';

  // 保存
  static Future<void> saveGoodsName(List<String> GoodsName) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.setStringList(_keyGoodsName, GoodsName);
  }

  // 获取
  static Future<List<String>?> getGoodsName() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.getStringList(_keyGoodsName);
  }

  // 清除
  static Future<void> clearGoodsName() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.remove(_keyGoodsName);
  }
}
//IMId的获取与存储
class IMIdManager {
  static const String _IMId = 'IMID';

  // 保存
  static Future<void> saveIMID(String userId) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.setString(_IMId, userId);
  }

  // 获取
  static Future<String?> getIMID() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.getString(_IMId);
  }

  // 清除
  static Future<void> clearIMID() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.remove(_IMId);
  }
}
//交易过司机手机号
class HisDriverPhoneManager {
  static const String _keyDriverPhone = 'Driverphone';

  // 保存
  static Future<void> saveDriverPhone(List<String> Driverphone) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.setStringList(_keyDriverPhone, Driverphone);
  }

  // 获取
  static Future<List<String>?> getDriverPhone() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.getStringList(_keyDriverPhone);
  }

  // 清除
  static Future<void> clearDriverPhone() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.remove(_keyDriverPhone);
  }
}